<?php
namespace app\business\controller;
use app\business\model\BusinessLogin;
use app\business\model\BusinessTableClassify;
use app\business\model\BusinessTable;
use think\Controller;
use app\business\controller\Base;
use think\Session;

class Tableclassify extends Base
{
    public function index()
    {
        $username = Session::get('username');

        $count = BusinessLogin::where('username',$username)->find();

        $num=$count['business_id']; //这个是当前商家

        $data = BusinessTableClassify::where('business_id',$num)->order(['classify_order' => 'desc'])->select();

        $this->assign('data',$data);

        return $this->fetch();
    }

    public function create()
    {
        return $this->fetch();
    }

    public function store()
    {


        $data = db('table_classify')->where('classify_name',$_POST['classify_name'])->find();

        if ($data) {
            return $this->error('该分类名称已存在，请重新填写！');
        }
        $username = Session::get('username');

        $count = BusinessLogin::where('username',$username)->find();

        $num=$count['business_id']; //这个是当前商家

        $_POST['business_id'] = $num;

        BusinessTableClassify::create($_POST);

        return redirect('index');
    }

    public function delete($id)
    {
        BusinessTableClassify::where('id',$id)->delete();

        return redirect('index');
    }

    public function edit($id)
    {
        $data = BusinessTableClassify::where('id',$id)->find();

        $this->assign('id',$id);

        $this->assign('data',$data);

        return $this->fetch();
    }

    public function update()
    {
        BusinessTableClassify::update($_POST);

        return redirect('index');
    }

}